package rickyGame.game.property
{
	import flash.utils.Dictionary;
	
	import ricky.Interface.IDispose;
	import ricky.game.Actor;
	
	import rickyGame.model.config.*;
	import  rickyGame.model.*;
	import rickyGame.game.Player;
	import rickyGame.game.skill.SkillData;

	/**
	 * 技能列表
	 * 
	 */
	public class Skill implements  IDispose
	{
		public function Skill(p:Actor=null)
		{
			_p=p;
			_mapSkill=new Dictionary();
			_learned=[];
			_passive=[];
			_auto=[];
		}
		
		/**
		 * 最多学习技能数目
		 */
		public function get upper():uint
		{
			return _upper;
		}

		/**
		 * @private
		 */
		public function set upper(value:uint):void
		{
			_upper = value;
		}

		/**
		 * 学习技能</br>
		 * 参数:</br>
		 * <b>abilityID:String</b> 技能ID
		 */
		public function learn(abilityID:String):void
		{
			if(abilityID=="")
				return;
			
			var skill:SkillData=new SkillData();
			var skillabi:Ability= ConfigUnitHelper.getAbilityConfig(abilityID);
			if(skillabi)
			{
				skill.load(skillabi);
				this._mapSkill[abilityID]=skill;
				_learned.push(skill);
				if(skill.auto)
					_auto.push(skill);
				else if(skill.passive)
					_passive.push(skill);
			}
		}
		
		/**
		 * 装载物理攻击技能
		 */
		public function learnAttack(abilityID:String="attack1"):void
		{
			var skill:SkillData=new SkillData();
			var skillabi:Ability= ConfigUnitHelper.getAbilityConfig(abilityID);
			if(skillabi)
			{
				skill.load(skillabi);
				this._attack1=skill;
			}
		}
		
		/**
		 * 提升技能
		 */
		public function upgradeSkill(abilityID:String):void
		{
			var c:SkillData=this._mapSkill[abilityID];
			var level:int=1;
			if(c)
				level=c.level+1;
			
			var skill:SkillData=new SkillData();
			var skillabi:Ability= ConfigUnitHelper.getAbilityConfig(abilityID);
			skill.load(skillabi,level);
			this._mapSkill[abilityID]=skill;
		}
	
		/**
		 * 得到技能
		 */
		public function getSkill(abilityID:String):SkillData
		{
			return _mapSkill[abilityID]
		}
		
		/**
		 * 得到以学的技能
		 */
		public function get learned():Array
		{
			return _learned;
		}

		/**
		 * 关联对象
		 */
		public function get player():Actor
		{
			return _p;
		}
		
		public function set player(value:Actor):void
		{
			_p = value;
		}

		public function get currSkill():SkillData
		{
			return _currSkill;
		}

		public function set currSkill(value:SkillData):void
		{
			_currSkill = value;
		}

		/**
		 * 物理攻击技能
		 */
		public function get attack1():SkillData
		{
			return _attack1;
		}

		public function set attack1(value:SkillData):void
		{
			_attack1 = value;
		}

		public function dispose():void
		{
			_passive.length=0;
			_auto.length=0;
			_learned.length=0;
			_mapSkill=new Dictionary();
			_currSkill=null;
			_attack1=null;
		}

		/**
		 * 自动施放的技能
		 */
		public function get auto():Array
		{
			return _auto;
		}

		/**
		 * 被动技能
		 */
		public function get passive():Array
		{
			return _passive;
		}
		
		private var _passive:Array;//被动技能
		private var _auto:Array;//自动技能
		private var _learned:Array;//学习过的技能
		private var _mapSkill:Dictionary;
		private var _p:Actor;
		private var _upper:uint=5;
		private var _currSkill:SkillData;
		
		private var _attack1:SkillData;//物理攻击
		
	}
}